package com.fzh.springboot.controller;

import com.fzh.springboot.utils.WebSocketUtil;
import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/ws/{sessionId}")
@Component
public class WebSocketController {

    @OnOpen
    public void onOpen(@PathParam("sessionId") String sessionId, Session session) {
        WebSocketUtil.onOpen(sessionId, session);
    }

    @OnClose
    public void onClose(@PathParam("sessionId") String sessionId, Session session) {
        WebSocketUtil.onClose(sessionId, session);
    }

    @OnMessage
    public void onMessage(@PathParam("sessionId") String sessionId, String message, Session session) {
        WebSocketUtil.onMessage(sessionId, message, session);
    }

    @OnError
    public void onError(@PathParam("sessionId") String sessionId,Session session, Throwable error) {
        WebSocketUtil.onError(sessionId, session, error);
    }
}
